package cn.huixh.blindbox.intercept;

import cn.huixh.blindbox.common.Common;
import cn.huixh.blindbox.service.TokenService;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author huixh
 * @version 1.0
 * @date 2022/5/9 13:41
 */
@Component
public class TokenInterceptor implements HandlerInterceptor {

    @Resource
    private TokenService tokenService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader(Common.TOKEN_KEY);

        tokenService.tokenVerify(token);
        return true;
    }

}
